package com.example.kotlindemo.`interface`

import java.io.File
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract

enum class Direction {
    EAST,
    WEST,
    SOUTH,
    NORTH
}


data class Coordinate(var x:Int,var y:Int)

enum class Direction2(private val coordinate: Coordinate){
    EAST(Coordinate(1,0)),
    WEST(Coordinate(1,0)),
    SOUTH(Coordinate(1,0)),
    NORTH(Coordinate(1,0));

    fun show(coordinate: Coordinate) {
        //todo

    }
}


sealed class My{
    object My1 :My()
    object My2 :My()
    class My3( val Myid:String):My()
}

class Driver(var status:My){
    fun check():String{
        return when(status){
            is My.My1 -> "my"
            is My.My2 -> "my"
            is My.My3 -> "my"
//            else -> {}
        }
    }
}

fun String.addExt(amount:Int = 1) = this + "!".repeat(count())

fun<T> T.easyprint():Unit = print(this)



public inline fun  File.apply(block: File.() -> Unit): File {
    block()
    return this
}


public inline fun <T> T.apply(block: () -> Unit): T {
    block()
    return this
}

fun main() {
    "asdf".easyprint()



    Direction.EAST is Direction
    Direction2.EAST.show(Coordinate(100,200))

    var file  = File("/s/s").apply {
        setReadable(true)
    }

    var file2  = File("/s/s").run(::isLong).run {  }.run {  }

    var result3 = with("iiiiiiiiiiii"){
        length > 10
    }

    var file99  = File("/s/s").takeIf {
//        it.absoluteFile = File("")
        it.canExecute()&&it.exists()
    }?.readLines()

    //1、定义扩展函数
    fun File.ext():Unit{
        setReadable(true)
    }
    //2、
    var block = File::ext

    File("")
        .apply(block)

    var str:String? = "luge"
    str = str?.let {
        if(it.isNotBlank()){
            it.capitalize()
        }else{
            ""
        }
    }

}

fun isLong(file: File): Any {
    return Int
}
